<?php

/**

 * Created by PhpStorm.

 * User: Administrator

 * Date: 2018/9/18

 * Time: 14:31

 */

namespace app\index\controller;
use app\common\trilateral\Classify as ClassifyAlias;
use app\index\model\Tyre;

use function GuzzleHttp\Psr7\str;

use think\Build;

use think\Request;

use app\index\model\Storemember as MemberModel;

use think\Exception;

use think\Cache;

use think\Loader;
use app\console\model\RefundOrderAudit;
use think\Db;

use think\View;

use app\common\PlsDemo;

use think\Url;

class Storemember

{

   public function member()

    {
        // 获取参数

        try {
			 $user_id = Request::instance()->param('user_id');
			 $shop_id = Request::instance()->param('shop_id');
			//查询店铺
			$shop_assignor_shop_id = Db::name('shop_assignor')->where(['id' => $user_id])->value('shop_id');
			
             if($shop_assignor_shop_id != $shop_id){
			 	 return ['code' => 401, 'message' => '店铺ID与登录会员店铺ID不对应'];
			 }else{
			 	$member_list = 
				Db::name('shop_assignor as a')
				//->join('job j', 'j.id = a.post')
				->join('shop s', 's.id = a.shop_id')
				->where(['a.id' => $user_id])
				->field('a.id as user_id,a.shop_id,s.shop_title,s.shop_name,a.name')
				->select();
				//var_dump($member_list);
				foreach ($member_list as $val) {
					$member_listb['user_id']=$val['user_id'];
					$member_listb['shop_id']=$val['shop_id'];
					$member_listb['shop_title']=$val['shop_title'];
					$member_listb['shop_name']=$val['shop_name'];
					$member_listb['name']=$val['name'];
					//$member_listb['job_title']=$val['job_title'];
					//$member_listb['job_id']=$val['job_id'];
					$member_lista[]=$member_listb;
				}
				//var_dump($member_list);
				//return ['code' => 200, 'message' => '登录成功', 'data' => ['user_id' => $user_id,'shop_id' => $shop_id_a]];
				return ['code' => 200, 'message' => '查询成功', 'data' =>$member_listb];
			 }
			
        } catch (Exception $e) {

            return ['code' => $e->getCode(), 'message' => $e->getMessage()];

        }



    }
	public function order_list()

    {
        // 获取参数

        try {
			 $param = Request::instance()->param();
		
			 $user_id = $param['user_id'];
			 $shop_id = $param['shop_id'];
			 //月份开始日期
			 //$begin_time = $param['time']."-01";
			 //月份结束日期
			 //$lastday = date('Y-m-d', strtotime("$begin_time +1 month -1 day"));
			 $begin_time = $param['begin_time']." 00:00:00";
			 $lastday = $param['end_time']." 23:59:59";
			 $type = $param['type'];
			 $where = [];
			 $zilei_he='';
			 if(!empty($param['top_id'])){
				if($param['order_type']=='2' || $param['order_type']=='3'){
				//查询所有属于这个分类的子类ID
				$zilei = Db::name('single')->where(['parent_id' =>$param['top_id']])->where(['is_delete' =>1])->select();
				foreach ($zilei as $k => &$v){
					$zilei_he .= $v['id'].",";
				}
				$zilei_he = rtrim($zilei_he, ',');
				//var_dump($zilei_he);
				//$where['sar.single_id'] = ['in',$zilei_he];
				$where['sar.single_id'] = ['eq',$param['top_id']];
				}else if($param['order_type']=='1'){
					//$zilei = Db::name('shop_goods')->where(['id' =>$param['top_id']])->where(['is_delete' =>1])->select();
					//查询所有属于这个分类的子类ID
					$zilei = Db::name('shop_goods')->where([['exp', "instr(CONCAT( ',', goods_str, ',' ),  ',".$param['top_id'].",' )" ]])->where(['is_delete' =>1])->select();
					foreach ($zilei as $k => &$v){
						$zilei_he .= $v['id'].",";
					}
					$zilei_he = rtrim($zilei_he, ',');
					$where['sar.single_id'] = ['in',$zilei_he];
				}
			 }
			 if(!empty($param['user_id'])) $where['sar.assignor_id'] = ['eq',$param['user_id']];
			 if(!empty($param['type'])) $where['sar.type'] = ['eq',$param['type']];
			 if (!empty($param['begin_time']) && !empty($param['end_time'])) {
				//$interval_timer = explode('/', $param['interval_timer']);
				$where['sar.create_time'] = ['between', [$begin_time,$lastday]];
				//$where['sar.create_time'] = ['between', [$begin_time,$lastday]];
			}
			//var_dump($where);
			if (!empty($param['order_type'])) {
				 $where['sar.order_type'] = ['eq',$param['order_type']];
			}
			if(!empty($param['assignor_content'])){
				if($param['order_type']=='2' || $param['order_type']=='3'){
					$where['sar.assignor_content'] = ['eq',$param['assignor_content']];
				}else if($param['order_type']=='1'){
					//根据传的分类ID查询出信息
					$zilei_he1='';
					$zilei1 = Db::name('shop_goods')->where(['goods_id' =>$param['assignor_content']])->where(['is_delete' =>1])->select();
					//var_dump($zilei1 );
					foreach ($zilei1 as $k => &$v){
						$zilei_he1 .= $v['id'].",";
					}
					$zilei_he1 = rtrim($zilei_he1, ',');
					$where['sar.assignor_content'] = ['in',$zilei_he1];
					//var_dump($zilei_he1);
					//$where['sar.assignor_content'] = ['eq',$param['assignor_content']];
				}
				
				
				
			}

			 /*if(!empty($param['begin_time'])){
				 $where['sar.create_time'] = ['egt',$param['begin_time']];
			 }
			 if(!empty($param['end_time'])){
				 $where['sar.create_time'] = ['elt',$param['end_time']];
			 }*/
			 $order_num = Db::name('shop_assignor_records as sar')->where(['saoma_status' => '2'])->where($where)->count();
			
			//var_dump($where);
			if($order_num=='0'){
				 return ['code' => 401, 'message' => '没有订单'];
			}else{
				//查询对应用户的服务器订单表 shop_assignor_record
				$order_lista = 
				Db::name('shop_assignor_records as sar')
				->join('shop s','sar.shop_id = s.id')
            	->join('shop_assignor sa', 'sar.assignor_id = sa.id', 'left')
            	->join('order o', 'sar.order_id = o.id')
				->join('member mm', 'o.member_id = mm.id')
            	->join('gift_card gc','o.order_number = gc.order_number','left')
				->where($where)
				->where(['sar.saoma_status' => '2'])
				->field('sar.*,sa.name,o.order_number,s.shop_title,o.car_number,o.amount,mm.username,mm.car_number as m_car_number,o.create_time,sar.create_time sc,gc.card_num,o.card_type')
            	->order('sar.id', 'desc')
				->select();
				
				$num ='0';
				//$order_list = [];
				/*
				 <th width="">订单ID</th>
                 <th width="">门店名称</th>
                 <th width="">订单号</th>
                 <th width="">用户账号</th>
                 <th width="">订单车牌号</th>
                 <th width="">订单类型</th>
                 <th width="">实体卡卡号</th>
                 <th width="">提成类型</th>
                 <th width="">服务人员</th>
                 <th width="">服务金额</th>
                 <th width="">服务分类</th>
                 <th width="">服务内容</th>
                 <th width="">订单总金额</th>
                 <th width="">是否同意</th>
                 <th>下单时间</th>
                 <th width="">服务时间</th>
				 <td>{$item.order_id}</td>
                 <td>{$item.shop_title}</td>
                 <td>{$item.order_number}</td>
                 <td>{$item.username}</td>
                 <td>{$item.car_number}</td>
                 <td>{switch item.order_type}
                 {case 1}商品订单{/case}
                 {case 2}服务订单{/case}
                 {case 3}礼包订单{/case}
                 {default /}无
                 {/switch}
                 {switch item.card_type}
                 {case 1}(礼包){/case}
                 {case 2}(实体卡){/case}
                 {default /}
                 {/switch}
                 </td>
                 <td>{$item.card_num}</td>
                 <td>{$item.type}</td>
                 <td>{$item.name}</td>
                 <td>{$item.assignor_price}</td>
                 <td>{$item.assignor_id}</td>
                 <td>{$item.assignor_content}</td>
                 <td>{$item.amount}</td>
                 <td>{$item.is_agree}</td>
                 <td>{$item.create_time}</td>
                 <td>{$item.sc}</td>
				*/
				
                foreach ($order_lista as $val) {
				   $num = $num + 1;	
                   $order_msg['num'] =$num;
				   $order_msg['shop_id'] =$val['shop_id'];
				   $order_msg['shop_title'] =$val['shop_title'];
				   //序号
				   $order_msg['num'] =$num;
				   //门店名称
				   $order_msg['shop_title'] = $val['shop_title'];
				   //订单车牌号
				   if($val['car_number']==''){
				   	 $order_msg['car_number'] = $val['m_car_number'];	
				   }else{
				   	$order_msg['car_number'] =$val['car_number'];
				   }
				  	
				   //买家账号
				   $order_msg['username'] = substr_replace($val['username'],'*****',2,5);
				   //订单类型
				   if($val['order_type']=='1'){
				   	 $order_msg['league']='商品订单';	
				   }elseif($val['order_type']=='2'){
				   	 $order_msg['league']='服务订单';	
				   }elseif($val['order_type']=='3'){
				   	 $order_msg['league']='礼包订单';	
				   }else{
				   	 $order_msg['league']='无';	
				   }
				   //订单类型下（礼包/实体卡）
				   if($val['card_type']=='1'){
				   	 $order_msg['league1']='(礼包)';	
				   }elseif($val['card_type']=='2'){
				   	 $order_msg['league1']='(实体卡)';	
				   }else{
				   	 $order_msg['league1']='无';	
				   }
				   //提成类型
				    if($val['type'] == 1){
						$order_msg['type'] = '服务提成';
					}
					if($val['type'] == 2){
						$order_msg['type'] = '销售提成';
					}
				   //销售人员
				   //服务人员
				   //服务金额
				   $order_msg['assignor_price']=$val['assignor_price'];
				   //服务分类
				   //$order_msg['parent_id']= Db::name('single')->where('id',$val['single_id'])->value('parent_id');
				   //服务内容
				   $order_msg['assignor_id']= Db::name('single')->where('id',$val['single_id'])->value('cat_name');
                   $order_msg['assignor_content']= Db::name('single')->where('id',$val['assignor_content'])->value('cat_name');
				  if($val['is_agree'] == 1){
                    	$order_msg['is_agree'] = '未同意';
					}else{
						$order_msg['is_agree'] = '已同意';
					}
					if($val['order_type'] == 1){
						$order_msg['assignor_content'] = Db::name('shop_goods')->where('id',$val['single_id'])->value('title');
						$goods_id = Db::name('shop_goods')->where('id',$val['single_id'])->value('goods_id');
						$order_msg['assignor_id'] = Db::name('goods_type')->where('id',$goods_id)->value('title');
					}
				   //订单总金额
				   $order_msg['amount']=$val['amount'];
				   //服务日期
				   $order_msg['sc']=$val['sc'];
				   $order_msg['create_time']=$val['create_time'];
				    $order_msg['order_number']=$val['order_number'];
					$order_msg['order_id']=$val['order_id'];
				   $order_list[]=$order_msg;
                }
			    //汇总金额：
				/*$order_id = Db::name('shop_assignor_records as sar')
					->join('shop_assignor sa', 'sar.assignor_id = sa.id', 'left')
					->join('order o', 'sar.order_id = o.id')
					->join('gift_card gc','o.order_number = gc.order_number','left')
					->where($where)
					->where(['sar.saoma_status' => '2'])
					->field('sar.*,sa.name,o.order_number')
					->order('sar.id', 'desc')
					//->where('is_agree',2)
					->group('sar.order_id')
					->column('sar.order_id');
				$order_amount = Db::name('order')->where('id','in',$order_id)->sum('amount');
				*/
				$order_amount = Db::name('shop_assignor_records sar')->where(['sar.saoma_status' => '2'])->where($where)->sum('assignor_price');
				//订单条数
				$order_sum =
				Db::name('shop_assignor_records as sar')
				->join('shop s','sar.shop_id = s.id')
				->join('shop_assignor sa', 'sar.assignor_id = sa.id', 'left')
				->join('order o', 'sar.order_id = o.id')
				->join('member mm', 'o.member_id = mm.id')
				->join('gift_card gc','o.order_number = gc.order_number','left')
				->where($where)
				->where(['sar.saoma_status' => '2'])
				->field('sar.*,sa.name,o.order_number,s.shop_title,o.car_number,o.amount,mm.username,mm.car_number as m_car_number,o.create_time,sar.create_time sc,gc.card_num,o.card_type')
				->order('sar.id', 'desc')
				->count();
				//订单总金额
				$order_all_price =
				Db::name('shop_assignor_records as sar')
				->join('shop s','sar.shop_id = s.id')
				->join('shop_assignor sa', 'sar.assignor_id = sa.id', 'left')
				->join('order o', 'sar.order_id = o.id')
				->join('member mm', 'o.member_id = mm.id')
				->join('gift_card gc','o.order_number = gc.order_number','left')
				->where($where)
				->where(['sar.saoma_status' => '2'])
				->field('sar.*,sa.name,o.order_number,s.shop_title,o.car_number,o.amount,mm.username,mm.car_number as m_car_number,o.create_time,sar.create_time sc,gc.card_num,o.card_type')
				->order('sar.id', 'desc')
				->sum('o.amount');
				$left_title = 
				array(
				'num'=>'序号',
				'shop_title'=>'门店名称',
				'car_number'=>'订单车牌号',
				'username'=>'买家账号',
				'league'=>'订单类型',
				'type'=>'提成类型',
				'assignor_price'=>'提成金额',
				'assignor_id'=>'服务分类',
				'assignor_content'=>'服务内容',
				'amount'=>'订单总金额',
				'sc'=>'服务日期'
				);
				return [
					'code' => 200,
					'message' => '查询成功',
					'left_title'=>$left_title,
					'order_amount'=>$order_amount,
					'order_list'=>$order_list,
					'order_sum'=>$order_sum,
					'order_all_price'=>$order_all_price
					];
			}
        } catch (Exception $e) {
			
            return ['code' => $e->getCode(), 'message' => $e->getMessage()];

        }



    }

	public function search(){
		try {
			 $param = Request::instance()->param();
			 $where = [];
			 if(empty($param['order_type'])){
			 	return ['code' => 401, 'message' => '请选择类型'];
			 }else{
				if($param['order_type']=='2' or $param['order_type']=='3'){
					//if(!empty($param['keyword'])){
						//$where['cat_name'] = ['like','%'.$param['keyword'].'%'];
					//}
					$where['parent_id'] = ['eq',0];
					$search_lista =
					Db::name('single')
					->where($where)
					->where(['is_delete' => '1'])
					->field('cat_name as title,id,parent_id')
					->order('id asc')
					->select();
					foreach ($search_lista as $val) {
					   $order_msg['title']=$val['title'];
					   $order_msg['id']=$val['id'];
					   $order_msg['parent_id']=$val['parent_id'];
					   $order_msg['two_list'] =Db::name('single')
						->where('parent_id', $val['id'])
						->where(['is_delete' => '1'])
						->field('cat_name as title,id,parent_id')
						->order('id asc')
						->select();
					   $search_list[]=$order_msg;
					}
					return [
						'code' => 200,
						'message' => '查询成功',
						'search_list'=>$search_list
						];
				}
				else if($param['order_type']=='1'){
					//if(!empty($param['keyword'])){
						//$where['title'] = ['like','%'.$param['keyword'].'%'];
					//}
					$where['parenTid'] = ['eq',0];
					
					$search_lista =
					Db::name('goods_type')
					->where($where)
					->where(['is_delete' => '1'])
					->field('title,id,parentStr,parenTid')
					->select();
					foreach ($search_lista as $val) {
					   $order_msg['title']=$val['title'];
					   $order_msg['id']=$val['id'];
					   //$conditiona[] = ;
					   //$order_msg['parent_id']=$val['parent_id'];
					   $order_msg['two_list'] =
					   Db::name('goods_type')
					   	->where([['exp', "instr(CONCAT( ',', parentStr, ',' ),  ',".$order_msg['id'].",' )" ]])
					   	->where(['is_delete' => '1'])
					   	->field('title,id')
					   	->order('id asc')
					   	->select();
					  //var_dump($order_msg['two_list']);
					  //var_dump($conditiona);
					   $search_list[]=$order_msg;
					}
					return [
						'code' => 200,
						'message' => '查询成功',
						'search_list'=>$search_list
						];
				}	
			 }
		} catch (Exception $e) {
		    return ['code' => $e->getCode(), 'message' => $e->getMessage()];
		}	 
	}



	 public function order_content()

    {
        // 获取参数

        try {
			$param = Request::instance()->param();
			$order_status = Db::name('shop_assignor_records')->where('order_id', $param['id'])->where('pici', $param['pici'])->where('assignor_id', '')->count();
			if($order_status=='0'){
				return ['code' => 401, 'message' => '请联系后台管理员创建服务人员与提成或批次'];
			}
			//查询对应批次对应岗位当前会员是否满足
			//查询当前会员的所属岗位
			
			$post_post = Db::name('shop_assignor')->where('id', $param['user_id'])->value('post');
			$post_status = Db::name('shop_assignor_records')->where('order_id', $param['id'])->where('pici', $param['pici'])->where('assignor_id', '')->where('post_id', 'in',$post_post)->count();
			if($post_status=='0'){
				return ['code' => 401, 'message' => '请联系后台管理员创建服务人员与提成或批次'];
			}
			//查询属于这个岗位的最新的提成
			$ttttt = Db::name('shop_assignor_records')
			->where('order_id', $param['id'])
			->where('pici', $param['pici'])
			->where('assignor_id', '')
			->where('post_id', 'in',$post_post)
			->limit(1)
			->order('id asc')
			->value('assignor_price');
			//var_dump($ttttt);
			// order -->order_id   order_type  1商品， 2 服务 3 礼包
			//根据订单查询类型
			$order_type = Db::name('order')->where('id','eq',$param['id'])->value('order_type');
			$id = $param['id'];
			$order_content = '';
			if($order_type=='1'){
				/****************************************************************************************************/
				$info = Db::name('order o')
				->join('member m', 'o.member_id = m.id','left')
				->join('shop s', 'o.shop_id = s.id','left')
				->field('o.*,m.username,m.is_certification,s.shop_title,m.car_number as m_car_number,m.brand_number,m.id_code')
				->where('o.id', $param['id'])
				->find();
				if($info['status'] == 10 || $info['status'] == 11 || $info['status'] == 12){
					$info['refund'] = Db::name('order_refund')->where('order_id',$info['id'])->field('explain,amount price,type')->find();
					$info['refund_create_time'] = Db::name('order_refund')->where('order_id',$info['id'])->value('create_time');
				}
				$info['goods_list'] = Db::name('order_goods og')
					->join('shop_goods sg', 'og.goods_id = sg.id','LEFT')
					->field('og.*,sg.thumb_img')
					->where('order_id', $id)
					->select();
				/*
					订单号
					买家账号
					门店名称
					车牌号
					是否认证
					绩效订单
					（线上/下）订单
					下单/退款时间
					总金额
					礼包金额--------->产品没有礼包金额
					优惠券使用情况
					买家留言
					支付方式
					支付类型
					礼包标题--产品没有礼包标题
					收货地址详情
					
				*/	
				if($info['is_certification']=='1'){
					$info['is_certification']='未认证';
				}elseif($info['is_certification']=='2'){
					$info['is_certification']='已认证';
				}elseif($info['is_certification']=='3'){
					$info['is_certification']='等待认证';
				}
				//绩效订单 finance_order
				if($info['finance_order']=='1'){
					$info['finance_order']='业务员订单';
				}elseif($info['finance_order']=='2'){
					$info['finance_order']='二维码订单';
				}elseif($info['finance_order']=='3'){
					$info['finance_order']='普通订单';
				}else{
					$info['finance_order']='-';
				}
				//线上/线下订单
				if($info['order_online']=='1'){
					$info['order_online']='线上订单';
				}elseif($info['order_online']=='2'){
					$info['order_online']='线下订单';
				}else{
					$info['order_online']='-';
				}
				//判断退款的
				if($info['status']=='10' or $info['status']=='11' or $info['status']=='12'){
					$info['refund_create_time']=$info['refund_create_time'];
				}else{
					$info['refund_create_time']='';
				}
				//优惠卷
				if($info['coupon_id'] >'0'){
					$info['coupon_content']="ID:".$info['coupon_id']."  标题：".$info['coupon_title']."-满：".$info['coupon_totol_price']."元-".$info['coupon_price']."元";
				}
				else{
					$info['coupon_content']='无';
				}
				//支付方式
				if($info['pay_way'] =='1'){
					$info['pay_way']="线上";
				}
				elseif($info['pay_way'] =='2'){
					$info['pay_way']='线下';
				}
				
				if($info['pay_type'] =='1'){
					$info['pay_type']="微信";
				}
				elseif($info['pay_type'] =='2'){
					$info['pay_type']='支付宝';
				}
				
				if($info['status'] =='1'){
					$info['status']='未支付';
				}elseif($info['status'] =='2'){
					$info['status']='已支付';
				}elseif($info['status'] =='3'){
					$info['status']='已发货';
				}elseif($info['status'] =='4'){
					$info['status']='已完成';
				}elseif($info['status'] =='5'){
					$info['status']='待评价';
				}elseif($info['status'] =='10'){
					$info['status']='退款中';
				}elseif($info['status'] =='11'){
					$info['status']='退款成功';
				}elseif($info['status'] =='12'){
					$info['status']='退款失败';
				}elseif($info['status'] =='20'){
					$info['status']='退款失败';
				}
				
				
				
				if($info['address_name']!='' or $info['address_phone']!='' or $info['area_info']!='' or $info['address']!=''){
					$info['address1']="姓名：".$info['address_name']."-手 机 号:".$info['address_phone']."-地　　区:".$info['area_info']."-详细地址:".$info['address'];
				}else{
					$info['address1']='';
				}
				if($info['car_number']==''){
				   	 $info['car_number'] = $info['m_car_number'];	
				   }else{
				   	$info['car_number'] =$info['car_number'];
				   }
				   
				$info['username'] =  substr_replace($info['username'],'******','1','6');    
				   
				$order_content =array(
				array('name'=>'订单号','value'=>$info['shop_order_number']),
				array('name'=>'买家账号','value'=>$info['username']),
				array('name'=>'门店名称','value'=>$info['shop_title']),
				array('name'=>'车牌号','value'=>$info['car_number']),
				array('name'=>'是否认证','value'=>$info['is_certification']),
				array('name'=>'绩效订单','value'=>$info['finance_order']),
				array('name'=>'（线上/下）订单','value'=>$info['order_online']),
				array('name'=>'下单/退款时间','value'=>$info['create_time']),
				array('name'=>'退款时间','value'=>$info['refund_create_time']),
				array('name'=>'总金额','value'=>$info['amount']),
				array('name'=>'优惠券使用情况','value'=>$info['coupon_content']),
				array('name'=>'买家留言','value'=>$info['explain']),
				//array('name'=>'支付方式','value'=>$info['pay_way']),
				array('name'=>'支付类型','value'=>$info['pay_type']),
				array('name'=>'收货地址详情','value'=>$info['address1']),
				array('name'=>'订单状态','value'=>$info['status']),
				//array('name'=>'商品列表','value'=>$info['goods_list']),
				
				/*'shop_order_number'=>$info['shop_order_number'],
				'username'=>$info['username'],
				'shop_title'=>$info['shop_title'],
				'car_number'=>$info['car_number'],
				'is_certification'=>$info['is_certification'],
				'finance_order'=>$info['finance_order'],
				'order_online'=>$info['order_online'],
				'create_time'=>$info['create_time'],
				'refund_create_time'=>$info['refund_create_time'],
				'amount'=>$info['amount'],
				'coupon_content'=>$info['coupon_content'],
				'explain'=>$info['explain'],
				'pay_way'=>$info['pay_way'],
				'pay_type'=>$info['pay_type'],
				'address'=>$info['address1'],
				'status'=>$info['status'],
				'goods_list'=>$info['goods_list']*/
				
				);
				/*$left_order = 
				array(
				'shop_order_number'=>'订单号',
				'username'=>'买家账号',
				'shop_title'=>'门店名称',
				'car_number'=>'车牌号',
				'is_certification'=>'是否认证',
				'finance_order'=>'绩效订单',
				'order_online'=>'（线上/下）订单',
				'create_time'=>'下单/退款时间',
				'refund_create_time'=>'退款时间',
				'amount'=>'总金额',
				'coupon_content'=>'优惠券使用情况',
				'explain'=>'买家留言',
				'pay_way'=>'支付方式',
				'pay_type'=>'支付类型',
				'address'=>'收货地址详情',
				'status'=>'订单状态',
				'goods_list'=>'商品列表'
				);*/
				//服务信息
				/*
					服务门店
					服务人员
					服务分类--商品没有分类
					服务内容
					提成金额
					消费日期
					用户是否确认使用
					类型
					
				*/
				
				//查询订单信息
				$order_product = Db::name('shop_assignor_records sar')
				->field('sar.*')
				->where('sar.order_id', $param['id'])
				->find();
				//查询当前会员的岗位ID
				
				
				
				
				$order_goods = Db::name('order_goods og')
				->field('og.title')
				->where('og.order_id', $param['id'])
				->select();
				//计算提成金额
				$ticheng = '0';
				
				
				$order_member = Db::name('shop_assignor sa')
				->field('sa.*')
				->where('sa.id', $param['user_id'])
				->find();
				
				if($order_product['is_agree']=='1'){
					$order_product['is_agree']='未同意';
				}elseif($order_product['is_agree']=='2'){
					$order_product['is_agree']='已同意';
				}
				
				if($order_product['type']=='1'){
					$order_product['type']='服务提成';
				}elseif($order_product['type']=='2'){
					$order_product['type']='销售提成';
				}
				$order_product1 = Db::name('shop_assignor_records sar')
				->field('sar.*')
				->where('sar.order_id', $param['id'])
				->find();
				if($order_product1['type']=='1'){
					$order_product1['type']='服务人员';
				}elseif($order_product1['type']=='2'){
					$order_product1['type']='销售人员';
				}
				
				
				
				/*
				$left_product = 
				array(
				'shop_title'=>'服务门店',
				'name'=>'服务人员',
				'title'=>'服务内容',
				'assignor_price'=>'提成金额',
				'create_time'=>'消费日期',
				'is_agree'=>'用户是否确认使用',
				'type'=>'类型',
				);
				*/
				$order_product1 =array(
				array('name'=>'服务门店','value'=>$info['shop_title']),
				array('name'=> $order_product1['type'],'value'=>$order_member['name']),
				//array('name'=>'服务内容','value'=>$info['title']),
				array('name'=>'提成金额','value'=>$ttttt),
				array('name'=>'消费日期','value'=>$order_product['create_time']),
				array('name'=>'用户是否确认使用','value'=>$order_product['is_agree']),
				array('name'=>'类型','value'=>$order_product['type']),
				/*'shop_title'=>$info['shop_title'],
				'name'=>$order_member['name'],
				'title'=>$order_goods,
				'assignor_price'=>$order_product['assignor_price'],
				'create_time'=>$order_product['create_time'],
				'is_agree'=>$order_product['is_agree'],
				'type'=>$order_product['type'],*/
				);
				
				
				
				
				/*
					订单号
					买家账号
					门店名称
					车牌号
					是否认证
					绩效订单
					（线上/下）订单
					下单/退款时间
					总金额
					礼包金额--------->产品没有礼包金额
					优惠券使用情况
					买家留言
					支付方式
					支付类型
					礼包标题--产品没有礼包标题
					收货地址详情
					
				*/	
				
				
				
				
				
				
				/*
				shop_order_number ->订单号
				username->买家账号
				car_number->车牌号
				shop_title->门店名称
				device-> 1是APP 2是小程序(APP/小程序)
				{:input('is_certification_text')}->是否认证
				finance_order->{switch name="item.finance_order"} 绩效订单
                                                    {case 1}业务员订单{/case}
                                                    {case 2}二维码订单{/case}
                                                    {case 3}门店订单{/case}
                                                    {case 4}普通订单{/case}
                                                    {default /}-
                                                    {/switch}
				order_online->(线上/下)订单：{switch name="item.order_online"}
                                                    {case 1}线上订单{/case}
                                                    {case 2}线下订单{/case}
                                                    {default /}-
                                                    {/switch}
				下单/退款时间：
				{$item.create_time}{in name="$item.status" value="10,11,12"} / {$item.refund_create_time}{/in}
				运费{$item.freight}
				总金额{$item.amount}
				退款金额{$refund.amount}-{switch name="$item.refund.type"}
                                                    {case 1}退款{/case}
                                                    {case 2}退货{/case}{/switch}
				退款理由{$refund.title}
				退款说明{$refund.explain}
				买家留言{$item.explain}
				支付方式{switch name="item.pay_way"}{case 1}线上{/case}{case 2}线下{/case}{/switch}																											
				优惠券使用情况 ID:{$item.coupon_id} 标题 : {$item.coupon_title}-满 : {$item.coupon_totol_price} 元 - {$item.coupon_price} 元
				配送方式
				{switch name="item.shipping"}{case 1}商家配送{/case}{case 2}到店自提{/case}{/switch}
				支付类型{switch name="item.pay_type"}{case 1}微信{/case}{case 2}支付宝{/case}{default /}-{/switch}
				收货地址详情 姓　　名：{$item.address_name}<br>
                                                手 机 号 ：{$item.address_phone}<br>
                                                地　　区：{$item.area_info}<br>
                                                详细地址：{$item.address}<br>
				订单状态{switch name="item.status"}
                                                {case 1}未支付{/case}
                                                {case 2}已支付{/case}
                                                {case 3}已发货{/case}
                                                {case 4}已完成{/case}
                                                {case 5}待评价{/case}
                                                {case 10}退款中{/case}
                                                {case 11}退款成功{/case}
                                                {case 12}退款失败{/case}
                                                {case 20}已取消({$item.cancel_content}){/case}
                                                {/switch}{if condition="$item.status eq 2"}
                                                <input type="checkbox" name="status"  value="3" datatype="*" nullmsg="请选择已发货！" > 已发货
                                                {/if}
												
				*/
				/************************/
				return ['code' => 200, 'message' => '查询成功','msg'=>'我是商品订单','order_content' =>$order_content,'order_product' =>$order_product1];	
			}elseif($order_type=='2'){
			
				/***************************************************************************************/
				$order = Db::name('order o')
				->join('member m', 'o.member_id = m.id','left')
	
				->join('single se', 'o.single_parent_id = se.id', 'left')
	
				->join('shop s', 'o.shop_id = s.id', 'left')
	
				->field('o.*,m.username,m.is_certification,o.car_number as o_car_number,m.car_number as m_car_number,m.brand_number,m.id_code,s.shop_title,se.cat_name')
	
				->where('o.id', $param['id'])
	
				->find();
				 $order['one_cat'] = Db::name('single')->where('id', $order['single_id'])->value('cat_name');
				 if($order['is_certification']=='1'){
					$order['is_certification']='未认证';
				}elseif($order['is_certification']=='2'){
					$order['is_certification']='已认证';
				}elseif($order['is_certification']=='3'){
					$order['is_certification']='等待认证';
				}
				if($order['car_number']==''){
					$order['car_number'] = $order['m_car_number'];
				}else{
					$order['car_number'] = $order['o_car_number'];
				}
				
				
				
				
				 //绩效订单 finance_order
				if($order['finance_order']=='1'){
					$order['finance_order']='业务员订单';
				}elseif($order['finance_order']=='2'){
					$order['finance_order']='二维码订单';
				}elseif($order['finance_order']=='3'){
					$order['finance_order']='普通订单';
				}else{
					$order['finance_order']='-';
				}
				
				//线上/线下订单
				if($order['order_online']=='1'){
					$order['order_online']='线上订单';
				}elseif($order['order_online']=='2'){
					$order['order_online']='线下订单';
				}else{
					$order['order_online']='-';
				}
				if($order['status'] == 10 || $order['status'] == 11 || $order['status'] == 12){
					$order['refund'] = Db::name('order_refund')->where('order_id',$order['id'])->field('explain,amount price,type')->find();
					$order['refund_create_time'] = Db::name('order_refund')->where('order_id',$info['id'])->value('create_time');
				}
				//判断退款的
				if($order['status']=='10' or $order['status']=='11' or $order['status']=='12'){
					$order['refund_create_time']=$order['refund_create_time'];
				}else{
					$order['refund_create_time']='';
				}
				
				//支付方式
				if($order['pay_way'] =='1'){
					$order['pay_way']="线上";
				}
				elseif($order['pay_way'] =='2'){
					$order['pay_way']='线下';
				}
				
				if($order['pay_type'] =='1'){
					$order['pay_type']="微信";
				}
				elseif($order['pay_type'] =='2'){
					$order['pay_type']='支付宝';
				}
				
				if($order['status'] =='1'){
					$order['status']='未支付';
				}elseif($order['status'] =='2'){
					$order['status']='已支付';
				}elseif($order['status'] =='3'){
					$order['status']='已发货';
				}elseif($order['status'] =='4'){
					$order['status']='已完成';
				}elseif($order['status'] =='5'){
					$order['status']='待评价';
				}elseif($order['status'] =='10'){
					$order['status']='退款中';
				}elseif($order['status'] =='11'){
					$order['status']='退款成功';
				}elseif($order['status'] =='12'){
					$order['status']='退款失败';
				}elseif($order['status'] =='20'){
					$order['status']='退款失败';
				}
				//服务方式
				if($order['shipping'] =='1'){
					$order['shipping']='商家配送';
				}elseif($order['shipping'] =='2'){
					$order['shipping']='到店自取';
				}
				
				if($order['shipping_name']!='' or $order['shipping_phone']!='' or $order['shipping_province']!='' or $order['shipping_address']!=''){
					$order['address1']="姓名：".$order['shipping_name']."-手 机 号:".$order['shipping_phone']."-地　　区:".$order['shipping_province']."-详细地址:".$order['shipping_address'];
				}else{
					$order['address1']='';
				}
				
				//1保险 2年检
				if ($order['service_type_id'] == 1 || $order['service_type_id'] == 2 || $order['service_type_id'] == 3) { 

					$order['service_info'] = Db::name('order_service')
		
						->where('order_id', $order['id'])
		
						->find();
		
					foreach (explode(',', $order['service_info']['type_id_str']) as $k => $v) {
		
						$order['service_info']['type_id_name'][] = Db::name('protect_type')->where('id', $v)->value('title');
		
					}
		
				}
				$order['username'] =  substr_replace($order['username'],'******','1','6'); 
				$order_content =array(
				array('name'=>'订单号','value'=>$order['order_number']),
				array('name'=>'买家账号','value'=>$order['username']),
				array('name'=>'门店名称','value'=>$order['shop_title']),
				array('name'=>'车牌号','value'=>$order['car_number']),
				array('name'=>'是否认证','value'=>$order['is_certification']),
				array('name'=>'绩效订单','value'=>$order['finance_order']),
				array('name'=>'（线上/下）订单','value'=>$order['order_online']),
				array('name'=>'下单/退款时间','value'=>$order['create_time']),
				array('name'=>'退款时间','value'=>$order['refund_create_time']),
				array('name'=>'订单金额','value'=>$order['amount']),
				array('name'=>'优惠券使用情况','value'=>$order['coupon_content']),
				array('name'=>'备注信息','value'=>$order['explain']),
				//array('name'=>'支付方式','value'=>$order['pay_way']),
				array('name'=>'支付类型','value'=>$order['pay_type']),
				array('name'=>'收货地址详情','value'=>$order['address1']),
				array('name'=>'订单状态','value'=>$order['status']),
				array('name'=>'服务金额','value'=>$order['order_price']),
				array('name'=>'所属分类','value'=>$order['cat_name']),
				array('name'=>'所属分类','value'=>$order['one_cat']),
				/*'order_number'=>$order['order_number'],
				'username'=>$order['username'],
				'shop_title'=>$order['shop_title'],
				'car_number'=>$order['car_number'],
				'is_certification'=>$order['is_certification'],
				'finance_order'=>$order['finance_order'],
				'order_online'=>$order['order_online'],
				'create_time'=>$order['create_time'],
				'refund_create_time'=>$order['refund_create_time'],
				'amount'=>$order['amount'],
				'coupon_content'=>$order['coupon_content'],
				'explain'=>$order['explain'],
				'pay_way'=>$order['pay_way'],
				'pay_type'=>$order['pay_type'],
				'address'=>$order['address1'],
				'status'=>$order['status'],
				'order_price'=>$order['order_price'],
				'shipping'=>$order['shipping'],
				'cat_name'=>$order['cat_name'],
				'one_cat'=>$order['one_cat']*/
				);
				$left_order = 
				array(
				'order_number'=>'订单号',
				'username'=>'买家账号',
				'shop_title'=>'门店名称',
				'car_number'=>'车牌号',
				'is_certification'=>'是否认证',
				'finance_order'=>'绩效订单',
				'order_online'=>'（线上/下）订单',
				'create_time'=>'下单/退款时间',
				'refund_create_time'=>'退款时间',
				'amount'=>'订单金额',
				'coupon_content'=>'优惠券使用情况',
				'explain'=>'备注信息',
				'pay_way'=>'支付方式',
				'pay_type'=>'支付类型',
				'address'=>'收货地址详情',
				'status'=>'订单状态',
				'order_price'=>'服务金额',
				'cat_name'=>'所属分类',
				'one_cat'=>'所属分类',
				);
				//服务信息
				/*
					服务门店
					服务人员
					服务分类--商品没有分类
					服务内容
					提成金额
					消费日期
					用户是否确认使用
					类型
					
				*/
				
				//查询订单信息
				$order_product = Db::name('shop_assignor_records sar')
				->field('sar.*')
				->where('sar.order_id', $param['id'])
				->find();
				
				$order_goods = Db::name('order_goods og')
				->field('og.title')
				->where('og.order_id', $param['id'])
				->select();
				//计算提成金额
				$ticheng = '0';
				
				
				$order_member = Db::name('shop_assignor sa')
				->field('sa.*')
				->where('sa.id', $param['user_id'])
				->find();
				
				if($order_product['is_agree']=='1'){
					$order_product['is_agree']='未同意';
				}elseif($order_product['is_agree']=='2'){
					$order_product['is_agree']='已同意';
				}
				
				if($order_product['type']=='1'){
					$order_product['type']='服务提成';
				}elseif($order_product['type']=='2'){
					$order_product['type']='销售提成';
				}
				
				$order_product1 = Db::name('shop_assignor_records sar')
				->field('sar.*')
				->where('sar.order_id', $param['id'])
				->find();
				if($order_product1['type']=='1'){
					$order_product1['type']='服务人员';
				}elseif($order_product1['type']=='2'){
					$order_product1['type']='销售人员';
				}
				
				
				/*$left_product = 
				array(
				'shop_title'=>'服务门店',
				'name'=>'服务人员',
				'cat_name'=>'服务分类',
				'one_cat'=>'服务内容',
				'assignor_price'=>'提成金额',
				'create_time'=>'消费日期',
				'is_agree'=>'用户是否确认使用',
				'type'=>'类型',
				);*/
				$order_product1 =array(
				array('name'=>'服务门店','value'=>$order['shop_title']),
				array('name'=>$order_product1['type'],'value'=>$order_member['name']),
				array('name'=>'服务分类','value'=>$order['cat_name']),
				array('name'=>'服务内容','value'=>$order['one_cat']),
				array('name'=>'提成金额','value'=>$ttttt),
				array('name'=>'消费日期','value'=>$order_product['create_time']),
				array('name'=>'用户是否确认使用','value'=>$order_product['is_agree']),
				array('name'=>'类型','value'=>$order_product['type']),
				/*'shop_title'=>$order['shop_title'],
				'name'=>$order_member['name'],
				'cat_name'=>$order['cat_name'],
				'one_cat'=>$order['one_cat'],
				'assignor_price'=>$order_product['assignor_price'],
				'create_time'=>$order_product['create_time'],
				'is_agree'=>$order_product['is_agree'],
				'type'=>$order_product['type'],*/
				);
				
				/***************************************************************************************/
			
				return ['code' => 200, 'message' => '查询成功','msg'=>'我是服务订单','order_content' =>$order_content,'order_product' =>$order_product1];	
			}elseif($order_type=='3'){
				$order = Db::name('order o')
				->join('member m', 'o.member_id = m.id','left')
	
				->join('single se', 'o.single_parent_id = se.id', 'left')
	
				->join('shop s', 'o.shop_id = s.id', 'left')
	
				->field('o.*,m.username,m.is_certification,o.car_number o_car_number,m.brand_number,m.id_code,s.shop_title,se.cat_name')
	
				->where('o.id', $param['id'])
	
				->find();
				 $order['one_cat'] = Db::name('single')->where('id', $order['single_id'])->value('cat_name');
				 if($order['is_certification']=='1'){
					$order['is_certification']='未认证';
				}elseif($order['is_certification']=='2'){
					$order['is_certification']='已认证';
				}elseif($order['is_certification']=='3'){
					$order['is_certification']='等待认证';
				}
				 //绩效订单 finance_order
				if($order['finance_order']=='1'){
					$order['finance_order']='业务员订单';
				}elseif($order['finance_order']=='2'){
					$order['finance_order']='二维码订单';
				}elseif($order['finance_order']=='3'){
					$order['finance_order']='普通订单';
				}else{
					$order['finance_order']='-';
				}
				
				//线上/线下订单
				if($order['order_online']=='1'){
					$order['order_online']='线上订单';
				}elseif($order['order_online']=='2'){
					$order['order_online']='线下订单';
				}else{
					$order['order_online']='-';
				}
				if($order['status'] == 10 || $order['status'] == 11 || $order['status'] == 12){
					$order['refund'] = Db::name('order_refund')->where('order_id',$order['id'])->field('explain,amount price,type')->find();
					$order['refund_create_time'] = Db::name('order_refund')->where('order_id',$info['id'])->value('create_time');
				}
				//判断退款的
				if($order['status']=='10' or $order['status']=='11' or $order['status']=='12'){
					$order['refund_create_time']=$order['refund_create_time'];
				}else{
					$order['refund_create_time']='';
				}
				
				//支付方式
				if($order['pay_way'] =='1'){
					$order['pay_way']="线上";
				}
				elseif($order['pay_way'] =='2'){
					$order['pay_way']='线下';
				}
				
				if($order['pay_type'] =='1'){
					$order['pay_type']="微信";
				}
				elseif($order['pay_type'] =='2'){
					$order['pay_type']='支付宝';
				}
				
				if($order['status'] =='1'){
					$order['status']='未支付';
				}elseif($order['status'] =='2'){
					$order['status']='已支付';
				}elseif($order['status'] =='3'){
					$order['status']='已发货';
				}elseif($order['status'] =='4'){
					$order['status']='已完成';
				}elseif($order['status'] =='5'){
					$order['status']='待评价';
				}elseif($order['status'] =='10'){
					$order['status']='退款中';
				}elseif($order['status'] =='11'){
					$order['status']='退款成功';
				}elseif($order['status'] =='12'){
					$order['status']='退款失败';
				}elseif($order['status'] =='20'){
					$order['status']='退款失败';
				}
				//服务方式
				if($order['shipping'] =='1'){
					$order['shipping']='商家配送';
				}elseif($order['shipping'] =='2'){
					$order['shipping']='到店自取';
				}
				
				if($order['shipping_name']!='' or $order['shipping_phone']!='' or $order['shipping_province']!='' or $order['shipping_address']!=''){
					$order['address1']="姓名：".$order['shipping_name']."-手 机 号:".$order['shipping_phone']."-地　　区:".$order['shipping_province']."-详细地址:".$order['shipping_address'];
				}else{
					$order['address1']='';
				}
				

				
				/*$order_content =array(
				
				'order_number'=>$order['order_number'],
				'username'=>$order['username'],
				'shop_title'=>$order['shop_title'],
				'car_number'=>$order['car_number'],
				'is_certification'=>$order['is_certification'],
				'finance_order'=>$order['finance_order'],
				'order_online'=>$order['order_online'],
				'create_time'=>$order['create_time'],
				'refund_create_time'=>$order['refund_create_time'],
				'amount'=>$order['amount'],
				'sale_price'=>$order['sale_price'],
				'coupon_content'=>$order['coupon_content'],
				'explain'=>$order['explain'],
				'order_online'=>$order['order_online'],
				'pay_type'=>$order['pay_type'],
				'gift_title'=>$order['gift_title'],
				);*/
				$order['username'] =  substr_replace($order['username'],'******','1','6'); 
				$order_content= array(
				array('name'=>'订单号','value'=>$order['order_number']),
				array('name'=>'买家账号','value'=>$order['username']),
				array('name'=>'门店名称','value'=>$order['shop_title']),
				array('name'=>'是否认证','value'=>$order['car_number']),
				array('name'=>'绩效订单','value'=>$order['is_certification']),
				array('name'=>'（线上/下）订单','value'=>$order['finance_order']),
				array('name'=>'下单/退款时间','value'=>$order['create_time']),
				array('name'=>'退款时间','value'=>$order['refund_create_time']),
				array('name'=>'总金额','value'=>$order['amount']),
				array('name'=>'礼包金额','value'=>$order['sale_price']),
				array('name'=>'优惠券使用情况','value'=>$order['coupon_content']),
				array('name'=>'买家留言','value'=>$order['explain']),
				array('name'=>'支付方式','value'=>$order['order_online']),
				array('name'=>'支付类型','value'=>$order['pay_type']),
				array('name'=>'礼包标题','value'=>$order['gift_title']),
				/*'order_number'=>'订单号',
				'username'=>'买家账号',
				'shop_title'=>'门店名称',
				'car_number'=>'车牌号',
				'is_certification'=>'是否认证',
				'finance_order'=>'绩效订单',
				'order_online'=>'（线上/下）订单',
				'create_time'=>'下单/退款时间',
				'refund_create_time'=>'退款时间',
				'amount'=>'总金额',
				'sale_price'=>'礼包金额',
				'coupon_content'=>'优惠券使用情况',
				'explain'=>'买家留言',
				'order_online'=>'支付方式',
				'pay_type'=>'支付类型',
				'gift_title'=>'礼包标题',*/
				);
				//服务信息
				/*
					服务门店
					服务人员
					服务分类--商品没有分类
					服务内容
					提成金额
					消费日期
					用户是否确认使用
					类型
					
				*/
				// 查询服务内容
				
				
				//查询订单信息
				$order_product = Db::name('shop_assignor_records sar')
				->field('sar.*')
				->where('sar.order_id', $param['id'])
				->where('sar.assignor_id', '')
				->find();
				
				$order_goods = Db::name('order_goods og')
				->field('og.title')
				->where('og.order_id', $param['id'])
				->select();
				//计算提成金额
				$ticheng = '0';
				
				$sn = Db::name('single sn')
				->field('sn.*')
				->where('sn.id', $order_product['assignor_content'])
				->find();
				
				
				$sn1 = Db::name('single sn')
				->field('sn.*')
				->where('sn.id', $sn['parent_id'])
				->find();
				
				$order_member = Db::name('shop_assignor sa')
				->field('sa.*')
				->where('sa.id', $param['user_id'])
				->find();
				
				if($order_product['is_agree']=='1'){
					$order_product['is_agree']='未同意';
				}elseif($order_product['is_agree']=='2'){
					$order_product['is_agree']='已同意';
				}
				
				if($order_product['type']=='1'){
					$order_product['type']='服务人员提成';
				}elseif($order_product['type']=='2'){
					$order_product['type']='礼包销售提成';
				}
				
				$order_product1 = Db::name('shop_assignor_records sar')
				->field('sar.*')
				->where('sar.order_id', $param['id'])
				->find();
				if($order_product1['type']=='1'){
					$order_product1['type']='服务人员';
				}elseif($order_product1['type']=='2'){
					$order_product1['type']='销售人员';
				}
				
				
				$left_product = 
				array(
				'shop_title'=>'服务门店',
				'name'=>'服务人员',
				'cat_name'=>'服务分类',
				'one_cat'=>'服务内容',
				'assignor_price'=>'提成金额',
				'create_time'=>'消费日期',
				'is_agree'=>'用户是否确认使用',
				'type'=>'类型',
				);
				
				
				$order_product1 =array(
				array('name'=>'服务门店','value'=>$order['shop_title']),
				array('name'=>$order_product1['type'],'value'=>$order_member['name']),
				array('name'=>'服务分类','value'=>$param['id'].$sn1['cat_name']),
				array('name'=>'服务内容','value'=>$sn['cat_name']),
				array('name'=>'提成金额','value'=>$ttttt),
				array('name'=>'消费日期','value'=>$order_product['create_time']),
				array('name'=>'用户是否确认使用','value'=>$order_product['is_agree']),
				array('name'=>'类型','value'=>$order_product['type']),
				
				
				/*'shop_title'=>$order['shop_title'],
				'name'=>$order_member['name'],
				'cat_name'=>$sn1['cat_name'],
				'one_cat'=>$sn['cat_name'],
				'assignor_price'=>$order_product['assignor_price'],
				'create_time'=>$order_product['create_time'],
				'is_agree'=>$order_product['is_agree'],
				'type'=>$order_product['type'],*/
				);
				
				/***************************************************************************************/
			
			
				return ['code' => 200, 'message' => '查询成功','msg'=>'我是礼包订单','order_content' =>$order_content,'order_product' =>$order_product1];	
			}
			
			//根据
			
			 /*$user_id = Request::instance()->param('user_id');
			 $shop_id = Request::instance()->param('shop_id');
			//查询店铺
			$shop_assignor_shop_id = Db::name('shop_assignor')->where(['id' => $user_id])->value('shop_id');
			
             if($shop_assignor_shop_id != $shop_id){
			 	 return ['code' => 401, 'message' => '店铺ID与登录会员店铺ID不对应'];
			 }else{
			 	$member_list = 
				Db::name('shop_assignor as a')
				->join('job j', 'j.id = a.post')
				->join('shop s', 's.id = a.shop_id')
				->where(['a.id' => $user_id])
				->field('a.id as user_id,a.shop_id,s.shop_title,s.shop_name,a.name,j.title as job_title,j.id as job_id')
				->select();
				return ['code' => 200, 'message' => '查询成功', 'data' =>$member_list];
			 }*/
			
        } catch (Exception $e) {

            return ['code' => $e->getCode(), 'message' => $e->getMessage()];

        }



    }



	public function code()

    {
        // 获取参数

        try {
			    $param = Request::instance()->param();
				$user_id =  $param['user_id'];
				if(is_numeric($param['id'])){
					$order_id = $param['id'];
					return ['code' => 401, 'message' => '请联系后台管理员确认批次'];
				}else{//left('sqlstudy.com', 3)lhmc6276277xml
					//$qu_qian =  substr($param['id'],4);
					$qu_qian = $param['id'];
					//后的数据
					$order_id1 = substr($qu_qian,strripos($qu_qian,"-")+1);
					//前的数据
					$order_id2 =  substr($qu_qian,0,strrpos($qu_qian ,"-"));
					$order_id =  $order_id2;
					//echo $order_id2."<br>";
					//echo $order_id1."<br>";
				}
				
			 $order_status = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('pici', $order_id1)->where('assignor_id', '')->count();
             if($order_status=='0'){
				return ['code' => 401, 'message' => '请联系后台管理员创建服务人员与提成或批次'];
			 }else{
			 	$user_shop_id = Db::name('shop_assignor')->where('id', $user_id)->where('is_delete', '1')->order('id', 'desc')->limit('0,1')->value('shop_id');
				return ['code' => 200, 'message' => '查询成功','shop_id'=>$user_shop_id,'order_id'=>$order_id,'pici'=>$order_id1];
			 }
			
        } catch (Exception $e) {
			
            return ['code' => $e->getCode(), 'message' => $e->getMessage()];

        }



    }

	 public function submit()

    {
        // 获取参数

        try {
		
			$param = Request::instance()->param();
			if(is_numeric($param['id'])){
				$order_id = $param['id'];
				$pici = $param['pici'];
			}else{//left('sqlstudy.com', 3)lhmc6276277xml
			
				$qu_qian = $param['id'];
				//后的数据
				$pici = substr($qu_qian,strripos($qu_qian,"-")+1);
				//前的数据
				$order_id =  substr($qu_qian,0,strrpos($qu_qian ,"-"));
				//$order_id =  $order_id2;
				//$qu_qian =  substr($param['id'],4);
				//$order_id =  substr($qu_qian,0,-3);
			}
			// order -->id   user_id-->user_id
			//$order_id = $param['id'];
			$user_id =  $param['user_id'];
			//$queren = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('assignor_id', $user_id)->update(['is_assignor_agree' => 2]);
			//先查询后台创建没创建这个的服务和销售
			$order_status = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('pici', $pici)->where('assignor_id', '')->where('post_id','neq','')->count();
			
			//查询当前会员对应的多个岗位ID
			$post = Db::name('shop_assignor')->where('id', $user_id)->where('is_delete', '1')->value('post');
			//查询这个订单的服务提成是否包含这个会员的岗位
			$post_status = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('pici', $pici)->where('assignor_id', '')->where('post_id','neq','')->where('post_id','in',$post)->count();
			
			//查询当前会员是不是这个岗位
			$post_id_new = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('assignor_id', '')->where('post_id','neq','')->order('id', 'desc')->limit('0,1')->value('post_id');
			//会员对应的门店ID
			$user_shop_id = Db::name('shop_assignor')->where('id', $user_id)->where('is_delete', '1')->order('id', 'desc')->limit('0,1')->value('shop_id');
			//这个订单有这个岗位的空白数据
			if($post_status=='0'){
				return ['code' => 401, 'message' => '请联系后台管理员创建对应岗位服务人员与提成'];
			}
			elseif($post_status >'0'){
				//查询最开始的一条对应会员岗位的数据
				$shop_assignor_id = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('assignor_id', '')->where('pici', $pici)->where('post_id','neq','')->where('post_id','in',$post)->order('id', 'asc')->limit('0,1')->value('id');
				$queren = Db::name('shop_assignor_records')
                    	->where('id', $shop_assignor_id)
                    	->update(['is_assignor_agree' => '2','assignor_id' => $user_id,'saoma_status'=>'2','create_time'=>date('Y-m-d H:i:s',time())]);
				if($queren){
					return ['code' => 200, 'message' => '确认成功','shop_id'=>$user_shop_id,'order_id'=>$order_id];
				}else{
					return ['code' => 401, 'message' => '确认失败'];
				}
			}
			die;
			
			
			//if(){
				
			//}
			
			if($order_status=='0'){
				return ['code' => 401, 'message' => '请联系后台管理员创建服务人员与提成'];
			}else{
			$queren = Db::name('shop_assignor_records')
                    	->where('order_id', $order_id)->where('assignor_id', '')->where('id', $id_d)
                    	->update(['is_assignor_agree' => '2','assignor_id' => $user_id,'saoma_status'=>'2']);
						if($queren){
							return ['code' => 200, 'message' => '确认成功','shop_id'=>$user_shop_id,'order_id'=>$order_id];
						}else{
							return ['code' => 401, 'message' => '确认失败'];
						}
				//会员对应的门店ID
				/*$user_shop_id = Db::name('shop_assignor')->where('id', $user_id)->where('is_delete', '1')->order('id', 'desc')->limit('0,1')->value('shop_id');
				//查询分类ID
				$assignor_content = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('assignor_id', '')->order('id', 'asc')->limit('0,1')->value('assignor_content');
				//会员对应的岗位ID
				$user_post_id = Db::name('shop_assignor')->where('id', $user_id)->where('is_delete', '1')->order('id', 'desc')->limit('0,1')->value('post');
				if($user_post_id !=''){
					//查询岗位百分比
					$ticheng  = Db::name('post_list')->where('shop_id', $user_shop_id)->where('cat_id', $assignor_content)->where('post_id', $user_post_id)->order('id', 'desc')->limit('0,1')->value('post_num');
				}else{
					$ticheng = '0';
				}
				
				//查询这个订单的类型 1是商品 2是服务 3是礼包
				$order_type = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('assignor_id', '')->order('id', 'asc')->limit('0,1')->value('order_type');
			
				//下面查询属于这个订单的人员为空的是服务提成还是销售提成
				$type = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('assignor_id', '')->order('id', 'asc')->limit('0,1')->value('type');
				$id_d = Db::name('shop_assignor_records')->where('order_id', $order_id)->where('assignor_id', '')->order('id', 'asc')->limit('0,1')->value('id');
				//1是服务提成
				//2是销售提成
				if($type=='1'){
					//商品订单的服务提成
					if($order_type=='1'){
						$assignor_price = '0';
						//提交服务提成
						$queren = Db::name('shop_assignor_records')
                    	->where('order_id', $order_id)->where('assignor_id', '')		
                    	->update(['assignor_price' => $assignor_price,'is_assignor_agree' => '2','assignor_id' => $user_id]);
						if($queren){
							return ['code' => 200, 'message' => '确认成功','shop_id'=>$user_shop_id,'order_id'=>$order_id];
						}else{   
							return ['code' => 401, 'message' => '确认失败'];
						}
						
					}elseif($order_type=='2'){//服务订单的服务提成
						//查询对应分类的服务提成
						//查询有没有提成
						$person_price1 = Db::name('shop_service_price')->where('shop_id', $user_shop_id)->where('single_id', $assignor_content)->count();
						if($person_price1=='0'){
							$person_price ='0'; 
							$price ='0'; 
						}else{
							$person_price = Db::name('shop_service_price')->where('shop_id', $user_shop_id)->where('single_id', $assignor_content)->value('person_price');  
							$price = Db::name('shop_service_price')->where('shop_id', $user_shop_id)->where('single_id', $assignor_content)->value('price');  
						}
						//计算总提成
						//$assignor_price = $ticheng*$price/100 + $person_price;
						$assignor_price = $ticheng + $person_price;
						echo "应提".$assignor_price."<br>";
						echo "原来的提成金额".$person_price."<br>";
						echo "价格".$price."<br>";
						echo "提成百分比".$ticheng."<br>";
						die;
						//提交服务提成
						$queren = Db::name('shop_assignor_records')
                    	->where('order_id', $order_id)->where('assignor_id', '')->where('id', $id_d)
						->update(['assignor_price' => $assignor_price,'is_assignor_agree' => '2','assignor_id' => $user_id]);
						if($queren){
							return ['code' => 200, 'message' => '确认成功','shop_id'=>$user_shop_id,'order_id'=>$order_id];
						}else{
							return ['code' => 401, 'message' => '确认失败'];
						}
					}elseif($order_type=='3'){//礼包订单的服务提成
						//查询对应分类的服务提成
						//查询有没有提成
						$person_price1 = Db::name('shop_service_price')->where('shop_id', $user_shop_id)->where('single_id', $assignor_content)->count();
						if($person_price1=='0'){
							$person_price ='0'; 
							$price ='0'; 
						}else{
							$person_price = Db::name('shop_service_price')->where('shop_id', $user_shop_id)->where('single_id', $assignor_content)->value('person_price');  
							$price = Db::name('shop_service_price')->where('shop_id', $user_shop_id)->where('single_id', $assignor_content)->value('price');  
						}
						//计算总提成
						$assignor_price = $ticheng + $person_price;
						echo "应提".$assignor_price."<br>";
						echo "原来的提成金额".$person_price."<br>";
						echo "价格".$price."<br>";
						echo "提成百分比".$ticheng."<br>";
						die;
						//提交服务提成
						$queren = Db::name('shop_assignor_records')
                    	->where('order_id', $order_id)->where('assignor_id', '')->where('id', $id_d)
                    	->update(['assignor_price' => $assignor_price,'is_assignor_agree' => '2','assignor_id' => $user_id]);
						if($queren){
							return ['code' => 200, 'message' => '确认成功','shop_id'=>$user_shop_id,'order_id'=>$order_id];
						}else{
							return ['code' => 401, 'message' => '确认失败'];
						}
					}
					//
					
				}elseif($type=='2'){
					if($order_type=='1'){
						
						//商品门店ID
						$cp_shop_id = Db::name('order_goods')->where('order_id', $order_id)->where('goods_id', $assignor_content)->value('shop_id');
						//查询数量
						$cp_number = Db::name('order_goods')->where('order_id', $order_id)->where('goods_id', $assignor_content)->value('number');
						//查询商品单价
						$cp_price = Db::name('shop_goods')->where('id', $assignor_content)->value('price');
						//合计
						$cp_price_heji =$cp_number * $cp_price;
						
						//计算这个商品的提成
						$person_price1 = Db::name('goods_shop_price')->where('goods_id', $assignor_content)->where('shop_id', $cp_shop_id)->count();
						if($person_price1=='0'){
							$cp_ticheng ='0';  
						}else{
							$cp_ticheng = Db::name('goods_shop_price')->where('goods_id', $assignor_content)->where('shop_id', $cp_shop_id)->value('price');
						}
						
						$assignor_price =$cp_ticheng*$cp_number;
						$queren = Db::name('shop_assignor_records')
                    	->where('order_id', $order_id)->where('assignor_id', '')->where('id', $id_d)
                    	->update(['assignor_price' => $assignor_price,'is_assignor_agree' => '2','assignor_id' => $user_id]);
						if($queren){
							return ['code' => 200, 'message' => '确认成功','shop_id'=>$user_shop_id,'order_id'=>$order_id];
						}else{
							return ['code' => 401, 'message' => '确认失败'];
						}
						 
					}elseif($order_type=='2'){
						//服务销售提成
						//查询这个服务订单是属于哪个门店的
						$fuwu_shop_id = Db::name('order')->where('id', $order_id)->value('shop_id');
						$fuwu_single_id= Db::name('order')->where('id', $order_id)->value('single_id');
						//计算提成
						$person_price1 = Db::name('single_shop_price')->where('shop_id', $fuwu_shop_id)->where('single_id', $fuwu_single_id)->count();
						if($person_price1=='0'){
							$assignor_price='0';
						}else{
							$assignor_price = Db::name('single_shop_price')->where('shop_id', $fuwu_shop_id)->where('single_id', $fuwu_single_id)->value('price');
						}
						$queren = Db::name('shop_assignor_records')
                    	->where('order_id', $order_id)->where('assignor_id', '')->where('id', $id_d)
                    	->update(['assignor_price' => $assignor_price,'is_assignor_agree' => '2','assignor_id' => $user_id]);
						if($queren){
							return ['code' => 200, 'message' => '确认成功','shop_id'=>$user_shop_id,'order_id'=>$order_id];
						}else{
							return ['code' => 401, 'message' => '确认失败'];
						}
						
					}elseif($order_type=='3'){
						//根据order_id查询出这个订单的销售提成
						$gift_id = Db::name('order')->where('id', $order_id)->value('gift_id');
						//礼包销售提成
						$person_price1 = Db::name('gift_shop_price')->where('shop_id', $user_shop_id)->where('gift_id', $gift_id)->count();
						if($person_price1=='0'){
							$person_price ='0'; 
							$price = Db::name('order')->where('id', $order_id)->value('amount');  
						}else{
							$person_price = Db::name('gift_shop_price')->where('shop_id', $user_shop_id)->where('gift_id', $gift_id)->value('price');  
							$price = Db::name('order')->where('id', $order_id)->value('amount');  
						}
						$assignor_price = $ticheng + $person_price;
						$queren = Db::name('shop_assignor_records')
                    	->where('order_id', $order_id)->where('assignor_id', '')->where('id', $id_d)
                    	->update(['assignor_price' => $assignor_price,'is_assignor_agree' => '2','assignor_id' => $user_id]);
						if($queren){
							return ['code' => 200, 'message' => '确认成功','shop_id'=>$user_shop_id,'order_id'=>$order_id];
						}else{
							return ['code' => 401, 'message' => '确认失败'];
						}
					}
				}*/
				
				
				//
				
				
				
				
			}
			
        } catch (Exception $e) {

            return ['code' => $e->getCode(), 'message' => $e->getMessage()];

        }



    }







}